package com.xiaojie.seata.order.impl.service.impl;


import com.xiaojie.seata.entity.Score;
import com.xiaojie.seata.order.impl.mapper.OrderMapper;
import com.xiaojie.seata.order.impl.service.feign.ScoreServiceFeign;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @author: xiaojie
 * @date: 2021.07.19
 */
@RestController
@Slf4j
public class OrderServiceImpl {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private ScoreServiceFeign scoreServiceFeign;

    @GetMapping("/finish")
    @GlobalTransactional
    public String finishOrder(Integer num){
        String xid = RootContext.getXID();
        log.info("xid>>>>>>>>>>>>>>>>>>>>:{}", xid);
        Integer integer = orderMapper.finishOrder("1");
        if (integer<0){
            return "修改订单失败";
        }
        //订单完成，添加积分
        Score score=new Score();
        score.setOrderId("111000");
        score.setUserId(123456L);
        String result= scoreServiceFeign.save(score);
        int i=1/num;
        return result;
    }
}
